import Vue from 'vue';
import Router from 'vue-router';

Vue.use(Router);

const routes = [
  {
    path: '*',
    redirect: '/chart'
  },

  {
    name: 'chart',
    component: () => import('./view/chart'),
    meta: {
      title: '运营详情'
    }
  },

  {
    name: 'scriptList',
    component: () => import('./view/script/ScriptList.vue'),
    meta: {
      title: '我的剧本'
    }
  },
  {
    name: 'applySetting',
    component: () => import('./view/script/ApplySetting.vue'),
    meta: {
      title: '申领配置'
    }
  },

  {
    name: 'applyList',
    component: () => import('./view/apply/ApplyList.vue'),
    meta: {
      title: '申领管理'
    }
  },

  {
    name: 'bindList',
    component: () => import('./view/bind/BindList.vue'),
    meta: {
      title: '扫码绑本'
    }
  },

  {
    name: 'storePower',
    component: () => import('./view/store/StorePower.vue'),
    meta: {
      title: '授权店铺'
    }
  },
  {
    name: 'couponGrant',
    component: () => import('./view/store/CouponGrant.vue'),
    meta: {
      title: '发放优惠券'
    }
  },

  {
    name: 'couponBatch',
    component: () => import('./view/coupon/BatchList.vue'),
    meta: {
      title: '优惠券'
    }
  },

  {
    name: 'about',
    component: () => import('./view/About.vue'),
    meta: {
      title: '关于我们'
    }
  },

];

// add route path
routes.forEach(route => {
  route.path = route.path || '/' + (route.name || '');
});

const router = new Router({ routes });

router.beforeEach((to, from, next) => {
  const title = to.meta && to.meta.title;
  if (title) {
    document.title = title;
  }
  next();
});

export {
  router
};
